#ifndef __M_LOG_H__
#define __M_LOG_H__

#include <cstdio>
#include <ctime>

// 日志等级
#define INF 0
#define DBG 1
#define ERR 2
#define DEFAULT_LOG_LEVEL DBG

const int g_num = 32;

/* 设置指定等级范围的日志输出 */
#define LOG(level, format, ...) do{\
    if(level < DEFAULT_LOG_LEVEL) break;\
    time_t t = time(NULL);\
    struct tm* lt = localtime(&t);\
    char time_buf[g_num] = { 0 };\
    strftime(time_buf, g_num - 1, "%Y/%m/%d-%H:%M:%S", lt);\
    fprintf(stdout, "[%s %s:%ld] " format "\n", time_buf, __FILE__, __LINE__, ##__VA_ARGS__);\
}while(0)
/*
__FILE__:获取调用宏的文件名
__LINE__:获取调用宏的行号
"str" format "str":连接字符串
*/

#define INF_LOG(format, ...) LOG(INF, format, ##__VA_ARGS__)
#define DBG_LOG(format, ...) LOG(DBG, format, ##__VA_ARGS__)
#define ERR_LOG(format, ...) LOG(ERR, format, ##__VA_ARGS__)

#endif